*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/
					
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A23
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	

use data/processed/data_1, clear

gen riskshare_retirwealth_Jan201=riskshare_retirwealth_Jan20
gen riskshare_ofinwealth_Jan201=riskshare_ofinwealth_Jan20
replace riskshare_retirwealth_Jan201=0 if retirJan20_0==1
replace riskshare_ofinwealth_Jan201=0 if ofinJan20_0==1
gen stockinvestor_retire=riskshare_retirwealth_Jan201>0 if riskshare_retirwealth_Jan201!=.
gen stockinvestor_ofin=riskshare_ofinwealth_Jan201>0 if riskshare_ofinwealth_Jan201!=.
gen delhhnetinc_USD_tr02_cond = delhhnetinc_USD_tr02 if jobloss_20q1==1
gen del_hhnetinc_perc_tr02_cond = del_hhnetinc_perc_tr02 if jobloss_20q1==1
gen delhhnetinc_USD_tr02_cond_qtr = delhhnetinc_USD_tr02_cond/4
	
* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02 {
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}

* gen conditional variables:
	gen del_ofin_perc_tr02_cond = del_ofin_perc_tr02
	replace del_ofin_perc_tr02_cond = . if stockinvestor_ofin!=1
	gen del_retir_perc_tr02_cond = del_retir_perc_tr02
	replace del_retir_perc_tr02_cond = . if stockinvestor_retire!=1
	gen del_finwealth_perc_tr02_cond = del_finwealth_perc_tr02
	replace del_finwealth_perc_tr02_cond = . if stockowner!=1

	gen delofin_USD_tr02_cond = delofin_USD_tr02
	replace delofin_USD_tr02_cond = . if stockinvestor_ofin!=1
	gen delretir_USD_tr02_cond = delretir_USD_tr02
	replace delretir_USD_tr02_cond = . if stockinvestor_retire!=1
	gen delfinwealth_USD_tr02_cond = delfinwealth_USD_tr02
	replace delfinwealth_USD_tr02_cond = . if stockowner!=1

* gen extensive margin vars:
	gen del_ofin_d = (del_ofin_perc_tr02<0) if  del_ofin_perc_tr02!=. 
	replace del_ofin_d = . if stockinvestor_ofin!=1
	
	gen del_retire_d = (del_retir_perc_tr02<0) if  del_retir_perc_tr02!=. 
	replace del_retire_d = . if stockinvestor_retire!=1
	
	gen del_finwealth_d = (del_finwealth_perc_tr02<0) if  del_finwealth_perc_tr02!=. 
	replace del_finwealth_d = . if stockowner!=1
	
	gen riskshare_5 = .
	replace riskshare_5=1 if riskshare_finwealth_Jan201>=0 &riskshare_finwealth_Jan201<=20 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=2 if riskshare_finwealth_Jan201>20 &riskshare_finwealth_Jan201<=40 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=3 if riskshare_finwealth_Jan201>40 &riskshare_finwealth_Jan201<=60 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=4 if riskshare_finwealth_Jan201>60 &riskshare_finwealth_Jan201<=80 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=5 if riskshare_finwealth_Jan201>80 &riskshare_finwealth_Jan201<=100 & riskshare_finwealth_Jan201!=.
	
keep if stockinvestor==1

* CHANGE IN FINANCAIAL WEALTH  
  
  * change in fin wealth by netwealth
	graph bar (mean)  del_finwealth_perc_tr02  , ///
		over(riskshare_5, relabel(1 "1-20" 2 "21-40" 3 "41-60" 4 "61-80" 5 "81-100") label(labsize(small) angle(45)))  ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5))  b1title(Net wealth quintile, size(medsmall)) ///
		bargap(0)  legend(off) /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-25(5)0, nogrid)  ysize(2) xsize(3) saving(Figures/temp1.gph, replace)
		
 * change in fin wealth by age	
	graph bar (mean) del_finwealth_perc_tr02, ///
				over(riskshare_5, relabel(1 "1-20" 2 "21-40" 3 "41-60" 4 "61-80" 5 "81-100") label(labsize(small) angle(45)))  ///
				over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title(Age group, size(medsmall)) ///
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-25(5)0, nogrid)  ysize(2) xsize(3)  saving(Figures/temp2.gph, replace)
	
* change in fin wealth by hh net income		
	graph bar (mean) del_finwealth_perc_tr02, ///
				over(riskshare_5, relabel(1 "1-20" 2 "21-40" 3 "41-60" 4 "61-80" 5 "81-100") label(labsize(small) angle(45)))  ///
				over(hhnetinc_2019_grp) b1title(Net income quintile, size(medsmall)) ///
		  bargap(0) ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-25(5)0, nogrid)  ysize(2) xsize(3) saving(Figures/temp3.gph, replace)
	
	graph combine 	Figures/temp1.gph ///
					Figures/temp3.gph ///
					Figures/temp2.gph ///
					, cols(1) rows(3) ysize(3) xsize(3) ///
					l1title("Change in financial wealth (%)", size(small)) ///
					b1title("January 2020 risky share allocation", size(small)) ///
					saving(Figures/tempx.gph, replace) iscale(0.55)
					 
	graph export Figures/FigureA23.pdf, as(pdf) fontface("cmr10") replace		
	graph export Figures/FigureA23.png, width(1600) replace		

	forvalues x = 1/3 {
		capture erase Figures/temp`x'.gph
}						
	capture erase Figures/tempx.gph																	
